package com.xnyzc.lhy.order.controller.approval;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.param.approval.ApplyAmountParam;
import com.xnyzc.lhy.order.entity.user.OaCUser;
import com.xnyzc.lhy.order.service.approval.IOaCRaiseApplyService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @Description 额度审批
 * @Author zhuyubin
 * @Date 2019/8/12 11:32
 **/
@RestController
@RequestMapping(value = "capi/oaCRaiseApply")
public class OaCRaiseApplyController {

    @Autowired
    private IOaCRaiseApplyService iOaCRaiseApplyService;

    /**
     * 申请额度
     * @param applyAmountParam 接参实体
     * @return
     */
    @PostMapping(value = "applyAmount")
    public Rv applyAmount(@ApiParam(value = "applyAmountParam", name = "applyAmountParam实体") @RequestBody ApplyAmountParam applyAmountParam){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        BigDecimal applyAmount = applyAmountParam.getApplyAmount();
        String applyReason = applyAmountParam.getApplyReason();
        Integer type = applyAmountParam.getType();
        if (CheckUtil.objIsEmpty(type, applyAmount, applyReason)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iOaCRaiseApplyService.applyAmount(userId, tag, type, applyAmount, applyReason));
    }
}
